package com.example.javapoet.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * JavaPoet示例项目的REST控制器
 */
@RestController
@RequestMapping("/api/javapoet")
public class JavaPoetController {

    /**
     * 获取项目信息
     */
    @GetMapping("/info")
    public Map<String, Object> getInfo() {
        Map<String, Object> info = new HashMap<>();
        info.put("name", "JavaPoet示例项目");
        info.put("description", "展示JavaPoet代码生成库的各种用法");
        info.put("version", "1.0.0");
        
        Map<String, String> categories = new HashMap<>();
        categories.put("basic", "基础用法示例");
        categories.put("intermediate", "中级用法示例");
        categories.put("advanced", "高级用法示例");
        categories.put("scenarios", "实际应用场景示例");
        
        info.put("categories", categories);
        
        return info;
    }
    
    /**
     * 获取JavaPoet基础用法示例
     */
    @GetMapping("/examples/basic")
    public Map<String, String> getBasicExamples() {
        Map<String, String> examples = new HashMap<>();
        examples.put("BasicClassGeneration", "生成基本的Java类");
        examples.put("BasicInterfaceGeneration", "生成Java接口");
        examples.put("BasicEnumGeneration", "生成枚举类型");
        examples.put("BasicAnnotationGeneration", "生成注解类型");
        return examples;
    }
    
    /**
     * 获取JavaPoet中级用法示例
     */
    @GetMapping("/examples/intermediate")
    public Map<String, String> getIntermediateExamples() {
        Map<String, String> examples = new HashMap<>();
        examples.put("GenericTypeGeneration", "生成带有泛型的类型");
        examples.put("ControlFlowGeneration", "生成包含控制流语句的代码");
        examples.put("JavadocGeneration", "生成带有Javadoc注释的代码");
        examples.put("LambdaAndMethodReferenceGeneration", "生成Lambda表达式和方法引用");
        return examples;
    }
    
    /**
     * 获取JavaPoet高级用法示例
     */
    @GetMapping("/examples/advanced")
    public Map<String, String> getAdvancedExamples() {
        Map<String, String> examples = new HashMap<>();
        examples.put("AnnotationProcessorGeneration", "生成注解处理器");
        examples.put("BuilderPatternGeneration", "生成Builder模式代码");
        examples.put("CodeGenerationWithReflection", "结合反射API生成代码");
        examples.put("VisitorPatternGeneration", "生成访问者模式代码");
        return examples;
    }
    
    /**
     * 获取JavaPoet应用场景示例
     */
    @GetMapping("/examples/scenarios")
    public Map<String, String> getScenarioExamples() {
        Map<String, String> examples = new HashMap<>();
        examples.put("RestApiGeneration", "生成REST API代码");
        examples.put("OrmMappingGeneration", "生成ORM映射代码");
        examples.put("TestCodeGeneration", "生成测试代码");
        return examples;
    }
}